package com.cxlin.cwanandroid

import android.app.Application
import android.content.Context
import com.cxlin.cwanandroid.di.appModule
import com.cxlin.cwanandroid.model.bean.User
import com.cxlin.cwanandroid.store.MMKVManager
import com.tencent.mmkv.MMKV
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
import kotlin.properties.Delegates

/**
 *
 * @Author: chenxunlin
 * @Date: 2024/4/26 14:06
 */
class App : Application() {

    companion object {
        var CONTEXT: Context by Delegates.notNull()
        var CURRENT_USER : User? = null
    }

    override fun onCreate() {
        super.onCreate()
        CONTEXT = applicationContext
        initMMKV()
        initDi()
        initUser()
    }

    /**
     * 依赖注入初始化
     */
    private fun initDi(){
        startKoin {
            androidContext(this@App)
            modules(appModule)
        }
    }

    private fun initMMKV(){
        MMKV.initialize(this)
    }

    /**
     * 初始化用户信息
     */
    private fun initUser(){
        CURRENT_USER = MMKVManager.user
    }

}